package css.gcu;
//林佳敏的克隆注释
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
public class SchoolSystem implements lSignUp{
    int big,medium,small;
    static String[] arr;   //各班剩余空位以及报名入学的人数的字符串数组
    static String[] bol;   //返回判断入学该班级是否还有空位的布尔值的字符串数组
    static int count;   //计算报名入学的人数
    public SchoolSystem(){    //构造方法

    }
    public SchoolSystem(int big,int medium,int small){     
        this.big = big;
        this.medium = medium;
        this.small = small;
    }
    public static void main(String[] args) throws Exception{
        lParams params = SchoolSystem.parse();
        SchoolSystem sc = new SchoolSystem(params.getBig(),params.getMedium(),params.getSmall());
        ArrayList<Integer> plan = params.getPlanSignUp();
        bol = new String[plan.size()];
        for(int i=0;i<plan.size();i++){
            bol[i] = new String(String.valueOf(sc.addStudent(plan.get(i))));
            count++;
        }
        sc.print();
    }
    public static lParams parse() throws Exception{
        Scanner in = new Scanner(System.in);
        System.out.println("输入:\n[\"SchoolSystem\",\"addStudent\",\"addStudent\",\"addStudent\"]");
        String total = in.nextLine();
        arr = parse(total);
        lParams ls = new lMenber();
        in.close();
        return ls;
        
    }
    public static String[] parse(String input){
        String regex = "[\\p{Punct}]";
        input = input.replaceAll(regex,"&");
        StringTokenizer fenxi = new StringTokenizer(input,"&");
        ArrayList<String> ar = new ArrayList<String> (); 
        while(fenxi.hasMoreTokens()){
            String item = fenxi.nextToken();
            int member = Integer.parseInt(item);
            ar.add(String.valueOf(member));
        }
        return ar.toArray(new String[ar.size()]);
    }

    
    @Override
    public void print() {    //输出
        // TODO Auto-generated method stub        
        System.out.print("[");
        for(int i=0;i<count+1;i++){
            if(i==0){
                System.out.print("null");
            }
            else{
                System.out.print(",");
                System.out.print(bol[i-1]);
            }
        }
        System.out.println("]");
    }

    @Override
    public boolean addStudent(int stuType) {
        // TODO Auto-generated method stub
        if(stuType==1){
            if(big!=0){
                big--;
                return true;
            }else{
                return false;
            }
        }
        else if(stuType==2){
            if(medium!=0){
                medium--;
                return true;
            }else{
                return false;
            }
        }
        else{
            if(small!=0){
                small--;
                return true;       
            }
            else{
                return false;
            }
        }

    }
}
